'use strict';

const BaseService = require('./base');

class UserTempService extends BaseService {

    async addTemp(tempInfo) {
        return new Promise(async (reslove, reject) => {
            let model = new this.ctx.model.UserTemp(tempInfo);
            await model.save((err, res) => {
                if (err) {
                    reject(err);
                } else {
                    reslove(res);
                }
            });
        });
    }

    async queryTemp(query) {
        return new Promise(async (reslove, reject) => {
            await this.ctx.model.UserTemp.find(query, (err, res) => {
                if (err) {
                    reject(err);
                } else {
                    reslove(res);
                }
            });
        });
    }

    async updateOneTemp(query, newDoc) {
        return new Promise(async (reslove, reject) => {
            await this.ctx.model.UserTemp.updateOne(query, newDoc, null, (err, res) => {
                if (err) {
                    reject(err);
                } else {
                    reslove(res);
                }
            });
        });
    }
}

module.exports = UserTempService;
